{extend name="common@base" /}
{block name="content"}
<section class="content">
  <div class="row">
    <div class="col-xs-12">
      <form action="" method="post" class="form">
        <div class="box box-primary">
          <div class="box-header with-border">
            <div class="box-title">请配置题型配比以及分值
              <small id="score"></small>
            </div>
          </div>
          <div class="box-body">
            {foreach $qType as $type=>$qt}
            <div class="form-inline">
              <label for="">{$qt}
                <input type="number" name="form[q_config][{$type}][num]"
                       value="{$qConfig ? $qConfig[$type][num] : 0}" class="form-control form-q"
                       min="1" max="100"> 题，</label>
              <label for="">单题分值
                <input type="number" name="form[q_config][{$type}][score]"
                       value="{$qConfig ? $qConfig[$type][score] : 0}" class="form-control form-q"
                       min="1" max="100"> 分</label>
            </div>
            {/foreach}
          </div>
        </div>
        <div class="box box-primary">
          <div class="box-header with-border">
            <div class="box-title">请设置考试基本信息</div>
          </div>
          <div class="box-body">
            <div class="form-inline">
              <label for="">考试时长
                <input type="number" name="form[exam_duration]" value="{$row.exam_duration}" class="form-control"
                       min="1" max="999"> 分钟
              </label>
            </div>
            <div class="form-inline">
              <label for="">通过分数
                <input type="number" name="form[pass_score]" value="{$row.pass_score}" class="form-control" min="1"
                       max="100"> 分
              </label>
            </div>
          </div>
        </div>
        <div class="box box-deafult">
          <div class="box-footer">
            <button class="btn btn-primary js-ajax-submit" type="submit">保存</button>
            <a href="javascript:history.back()" class="btn btn-default">返回</a>
          </div>
        </div>

      </form>
    </div>
  </div>
</section>
{/block}
{block name="page_script"}
<script>
  require(["layer_config", "ajaxForm"], function (layer) {
    countScore();
    $(".form-q").on("input", function () {
      countScore()
    });

    function countScore() {
      var objs = $(".form-q");
      var obj=$("#score");
      var score = objs.eq(0).val() * objs.eq(1).val();
      score = score + objs.eq(2).val() * objs.eq(3).val();
      if(score!=100){
        obj.addClass('label-danger');
      }else{
        obj.removeClass('label-danger');
      }
      obj.text(score+"分");
    }
  });

</script>
{/block}




